package com.pai4j.common.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 创作者等级枚举
 *
 * @author: CYM-pai
 * @date: 2025/11/01
 */
@Getter
@AllArgsConstructor
public enum CreatorLevelEnum {
    
    BEGINNER(1, "新手创作者", 0, 1000),
    INTERMEDIATE(2, "进阶创作者", 1000, 5000),
    ADVANCED(3, "高级创作者", 5000, 20000),
    EXPERT(4, "专家创作者", 20000, 100000),
    MASTER(5, "大师创作者", 100000, Integer.MAX_VALUE);
    
    private final Integer level;
    private final String name;
    private final Integer expMin;
    private final Integer expMax;
    
    /**
     * 根据等级获取枚举
     */
    public static CreatorLevelEnum getByLevel(Integer level) {
        if (level == null) {
            return null;
        }
        for (CreatorLevelEnum levelEnum : CreatorLevelEnum.values()) {
            if (levelEnum.getLevel().equals(level)) {
                return levelEnum;
            }
        }
        return null;
    }
    
    /**
     * 根据经验值获取对应等级
     */
    public static CreatorLevelEnum getByExperience(Integer experience) {
        if (experience == null || experience < 0) {
            return BEGINNER;
        }
        for (CreatorLevelEnum levelEnum : CreatorLevelEnum.values()) {
            if (experience >= levelEnum.getExpMin() && experience < levelEnum.getExpMax()) {
                return levelEnum;
            }
        }
        return MASTER;
    }
}




